﻿using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using FitNesseRunner;

namespace FitNesseRunnerTests
{
	static class CollectionAssertEx
	{
		private const string CollectionMessageFormat = "\nExpected:\n{0}\n\nActual:\n{1}\n\n";

		public static void AreEquivallent<T>(IEnumerable<T> expected, IEnumerable<T> actual)
		{
			CollectionAssert.AreEquivalent(expected.ToList(), actual.ToList(), CollectionMessageFormat, ToString(expected), ToString(actual));
		}

		public static void AreEqual<T>(IEnumerable<T> expectedResult, IEnumerable<T> actual)
		{
			CollectionAssert.AreEqual(expectedResult.ToList(), actual.ToList(), CollectionMessageFormat, ToString(expectedResult), ToString(actual));
		}

		private static string ToString<T>(IEnumerable<T> expectedResult)
		{
			return string.Join(", \n", expectedResult);
		}

		public static void IsEmpty(IEnumerable collection)
		{
			Assert.IsFalse(collection.Any());
		}

		public static void Contains<T>(T expectedElement, IEnumerable<T> collection)
		{
			CollectionAssert.Contains(collection.ToList(), expectedElement, "Element '{0}' is not found in [<{1}>]", expectedElement, string.Join(">; <", collection));
		}

		public static void IsEmpty<T>(IEnumerable<T> collection, string message)
		{
			Assert.IsFalse(collection.Any(), message);
		}
	}
}
